package com.ruoyi.training.service.impl;

import java.util.List;
import com.ruoyi.common.core.utils.DateUtils;
import com.ruoyi.training.dto.SatisfactionSurveyDto;
import com.ruoyi.training.util.xuehua.SnowflakeIdUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.training.mapper.SatisfactionSurveyMapper;
import com.ruoyi.training.domain.SatisfactionSurvey;
import com.ruoyi.training.service.ISatisfactionSurveyService;

/**
 * 满意度调查结果Service业务层处理
 * 
 * @author lqx
 * @date 2025-11-11
 */
@Service
public class SatisfactionSurveyServiceImpl implements ISatisfactionSurveyService 
{
    @Autowired
    private SatisfactionSurveyMapper satisfactionSurveyMapper;

    /**
     * 查询满意度调查结果
     * 
     * @param satisfactionSurveyId 满意度调查结果主键
     * @return 满意度调查结果
     */
    @Override
    public SatisfactionSurvey selectSatisfactionSurveyBySatisfactionSurveyId(String satisfactionSurveyId)
    {
        return satisfactionSurveyMapper.selectSatisfactionSurveyBySatisfactionSurveyId(satisfactionSurveyId);
    }

    /**
     * 查询满意度调查结果列表
     * 
     * @param satisfactionSurvey 满意度调查结果
     * @return 满意度调查结果
     */
    @Override
    public List<SatisfactionSurvey> selectSatisfactionSurveyList(SatisfactionSurvey satisfactionSurvey)
    {
        return satisfactionSurveyMapper.selectSatisfactionSurveyList(satisfactionSurvey);
    }

    /**
     * 新增满意度调查结果
     * 
     * @param satisfactionSurvey 满意度调查结果
     * @return 结果
     */
    @Override
    public int insertSatisfactionSurvey(SatisfactionSurvey satisfactionSurvey)
    {
        satisfactionSurvey.setCreateTime(DateUtils.getNowDate());
        satisfactionSurvey.setSatisfactionSurveyId(String.valueOf(new SnowflakeIdUtils(5, 8).nextId()));
        return satisfactionSurveyMapper.insertSatisfactionSurvey(satisfactionSurvey);
    }

    /**
     * 修改满意度调查结果
     * 
     * @param satisfactionSurvey 满意度调查结果
     * @return 结果
     */
    @Override
    public int updateSatisfactionSurvey(SatisfactionSurvey satisfactionSurvey)
    {
        return satisfactionSurveyMapper.updateSatisfactionSurvey(satisfactionSurvey);
    }

    /**
     * 批量删除满意度调查结果
     * 
     * @param satisfactionSurveyIds 需要删除的满意度调查结果主键
     * @return 结果
     */
    @Override
    public int deleteSatisfactionSurveyBySatisfactionSurveyIds(String[] satisfactionSurveyIds)
    {
        return satisfactionSurveyMapper.deleteSatisfactionSurveyBySatisfactionSurveyIds(satisfactionSurveyIds);
    }

    /**
     * 删除满意度调查结果信息
     * 
     * @param satisfactionSurveyId 满意度调查结果主键
     * @return 结果
     */
    @Override
    public int deleteSatisfactionSurveyBySatisfactionSurveyId(String satisfactionSurveyId)
    {
        return satisfactionSurveyMapper.deleteSatisfactionSurveyBySatisfactionSurveyId(satisfactionSurveyId);
    }

    /**
     * 通过班级id和查询参数查询满意度调查结果列表
     * lqx
     */
    @Override
    public List<SatisfactionSurveyDto> selectSatisfactionSurveyListBySatisfactionSurveyDto(SatisfactionSurveyDto satisfactionSurveyDto) {
        List<SatisfactionSurveyDto> satisfactionSurveyDtos = satisfactionSurveyMapper.selectSatisfactionSurveyListBySatisfactionSurveyDto(satisfactionSurveyDto);
        for (SatisfactionSurveyDto surveyDto : satisfactionSurveyDtos) {
            if (!"".equals(surveyDto.getSatisfactionSurveyStatus()) && surveyDto.getSatisfactionSurveyStatus() != null){
                if ("0".equals(surveyDto.getSatisfactionSurveyStatus())){
                    surveyDto.setSatisfactionSurveyStatusName("已填报");
                }else {
                    surveyDto.setSatisfactionSurveyStatusName("未填报");
                }
            }
        }
        return satisfactionSurveyDtos;
    }

    /**
     * 通过班级id和学员id查询满意度调查结果列表
     * lqx
     */
    @Override
    public SatisfactionSurvey selectSatisfactionSurveyListByByStudentIdAndClassId(String trainingClassId, String studentId) {
        return satisfactionSurveyMapper.selectSatisfactionSurveyListByByStudentIdAndClassId(trainingClassId,studentId);
    }
}
